package app.netant.book.ltxswang;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class LtxswangDetail extends BaseDetail {

	public LtxswangDetail(String netSite) {
		super(netSite);
		this.preHref = "https://www.ltxswang.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("#conn #maininfo .coverecom.left #bookinfo .bookright .d_title h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
		
		Elements parts1 = this.select("#conn #maininfo .coverecom.left #bookinfo .bookright .d_title .p_author");
		if(parts1.size()>0){
			String writer = parts1.get(0).text();
			int idx = writer.indexOf("：");
			if(idx>0){
				writer = writer.substring(idx+1).trim();
			}
			System.out.println("【Writer】:"+writer);
			this.entity.setNovelWriter(writer);
		}
		
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("#conn #maininfo .coverecom.left #bookinfo .bookright #count");
		if(parts.size()>0){
			String tags = parts.get(0).text();
			this.splitTags(tags, true);
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("#conn #maininfo .coverecom.left #bookinfo .bookright #bookintro #showinfo .d2");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
		
		Elements parts1 = this.select("#conn #maininfo .coverecom.left #bookinfo .bookright #keywords");
		if(parts1.size()>0){
			String date = parts1.get(0).text();
			int idx = date.indexOf("：");
			if(idx>0){
				date = date.substring(idx+1);
				System.out.println("【Date】:"+date);
				this.entity.setNovelDate(date);
			}
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("#conn #maininfo .coverecom.left #bookinfo #button_all ul li.li3 a");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text();
			if(text.indexOf("下载")>=0){
				String href = parts.get(i).attr("href");
				if(href.startsWith("/")){
					href = this.preHref + href;
				}
				System.out.println("【Href】："+href);
				this.entity.setDownPath(href);
			}
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("#conn #maininfo .coverecom.left .tabstit a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		LtxswangDetail detail = new LtxswangDetail("https://www.ltxswang.com/book/9632.html");
		detail.test();
	}



}
